﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Battle
{
    public class Enemy_Num : EnemyBase
    {
        private TextMesh numText;
        private int _Num;
        public int Num
        {
            get => _Num;
            set
            {
                _Num = value;
                if (numText != null)
                    numText.text = _Num.ToString();
            }
        }

        protected override void Awake()
        {
            numText = GetComponentInChildren<TextMesh>();
            Num = 20;

            base.Awake();
        }

        public Enemy_Num InitEnemy(Vector3 bornPos, int hp, float speed)
        {
            Hp = hp;
            Num = hp;
            GoldReward = hp;
            ScienceReward = Mathf.Max(1, hp / 10);

            transform.position = bornPos;
            Vector3 target = new Vector3(bornPos.x, -5f, bornPos.z);
            if (MoveComponent == null)
                MoveComponent = gameObject.AddComponent<EnemyMoveBase>();

            MoveComponent.Init(target, speed);
            return this;
        }

        public override void OnHit(ST_HitActionData hitActionData)
        {
            base.OnHit(hitActionData);
            Num = (int)Hp;
        }
    }
}
